package com.alibaba.controller;

import com.alibaba.entity.User;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhuangzhiwen
 * @Date: 2021/8/22
 */
public class Fanxing {
    public void test01(Map<String,User> map, List<String> list){
        System.out.println("test01");
    }

    public Map<String ,User > test02(){
        System.out.println("test02");
        return null;
    }

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        Class c1 = Class.forName("com.alibaba.controller.Fanxing");
        Method m = c1.getMethod("test01", Map.class, List.class);
        for (Type type : m.getGenericParameterTypes()) {
            System.out.println(type);
            System.out.println("------");
            if(type instanceof ParameterizedType){
                Type[] actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments();
                for (Type actualTypeArgument : actualTypeArguments) {
                    System.out.println(actualTypeArgument);
                }
            }
        }
        System.out.println("=======");
        Method m2 = c1.getMethod("test02", null);
        Type genericReturnType = m2.getGenericReturnType();
        if(genericReturnType instanceof ParameterizedType){
            Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
            for (Type actualTypeArgument : actualTypeArguments) {
                System.out.println(actualTypeArgument);
            }
        }

    }
}
